<% /* $Id: submit.jsp 132 2011-08-26 10:23:42Z altdotua@gmail.com $ */ %>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%@ include file="header.jsp" %>

<h1 align="center">
	<%= bundle.getString("W_SUBMIT_SOLUTION") %>
</h1>

<%
	if (user == null)
	{
		response.sendRedirect(Linker.link("login.jsp?return=" + URLEncoder.encode(request.getRequestURI(), AbstractServlet.defaultEncoding)));
		return;
	}
	if ((contest.getStartTime().after(new Date()) || contest.getFinishTime().before(new Date())) && !user.isAdmin())
		return;
%>

<div align="center">
	<form action="<%= Linker.link("/submissions") %>" method="post">
		<input type="hidden" name="action" value="submit">
		<input type="hidden" name="return" value="<%= Linker.link("submissions.jsp") %>">
		<input type="hidden" name="contestId" value="<%= contest.getId() %>">
		<table>
			<tr>
				<td><%= bundle.getString("W_PROBLEM") %></td>
				<td><select name="problemId">
				<%
					HashMap<String, Object> map = new HashMap<String, Object>();
					map.put("contestId", contest.getId());
					if (!user.isAdmin())
					{
						map.put("active", true);
						map.put("visible", true);
					}			
					List<ContestProblemEntry> problems = ContestProblemsModel.getEntries(map);
					String problemId = request.getParameter("problem_id");
					for (ContestProblemEntry problem : problems)
					{
				%>
					<option value="<%= problem.getId() %>" <%= problem.getId().toString().equals(problemId) ? " selected=\"selected\"" : "" %>><%= problem %> 
				<%
				 	}
 				%>
					</select>
				</td>
			</tr>
			<tr>
				<td><%= bundle.getString("W_LANGUAGE") %></td>
				<td><select name="languageId">
				<%
					List<LanguageEntry> languages = ContestLanguagesModel.getContestEntries(contest.getId());
					String languageId = request.getParameter("language_id");
					for (LanguageEntry language : languages)
					{
				%>
						<option value="<%= language.getId( ) %>" <%= language.getId().toString().equals(language) || language.getId().toString().equals(request.getSession().getAttribute("language")) ? " selected=\"selected\"" : "" %>><%= language %>
				<%
	 				}
				%>
					</select>
				</td>
			</tr>
			<tr>
				<td colspan="2"><textarea name="sourceCode" rows="20" cols="50"></textarea></td>
			</tr>
			<%
				Boolean allowFirstTest = contest.getAllowFirstTestOnly();
				if (allowFirstTest != null && Boolean.TRUE.equals(allowFirstTest))
				{
			%>
			<tr>
				<td colspan="2"><input type="checkbox" name="fFirstTestOnly" checked="checked"><%= bundle.getString("W_FIRST_TEST_ONLY") %></td>
			</tr>
			<%
				}
			%>
			<tr>
				<td colspan="2" align="center"><input type="submit" value="<%= bundle.getString("W_SUBMIT") %>"></td>
			</tr>
		</table>
	</form>
</div>
<br />

<%@ include file="footer.jsp" %>